package com.sh.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sh.dao.BookDao;
import com.sh.entity.Book;
import com.sh.entity.Computers;
import com.sh.util.Result;

@RestController
public class BookController {
	@Autowired
	private BookDao bookDao;

	@RequestMapping("/selectBook")
	public Result getAll(Integer limit, Integer page, Book book, Map<String, Object> map) {
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		map.put("bookName", book.getBookName());
		map.put("bookPress", book.getBookPress()); // 存取页数和前台传来的数据
		List<Map<String, Object>> getAlList = bookDao.getAll(map);
		Integer getInteger = bookDao.getCount();
		Result result = new Result(true, 0, null, getInteger, getAlList);
		return result;
	}

	// 添加
	@RequestMapping("/insertBook")
	public Result insertBook(Book book) {
		int inserts = bookDao.insertBook(book);
		Result res = new Result(200, "", inserts, true);
		return res;
	}

	// 修改
	@RequestMapping("/updateBook")
	public Result updateBook(Book book) {
		Integer updates = bookDao.updateBook(book);
		Result res = new Result(200, "", updates, true);
		return res;
	}

	// 删除
	@RequestMapping("/deleteBook")
	public Result deleteComputers(Integer bookid) {
		int i = bookDao.deleteBook(bookid);
		Result res = new Result(200, "", i, true);
		return res;

	}

}
